/* Y o u r   D e s c r i p t i o n                       */
/*                            AppBuilder Photon Code Lib */
/*                                         Version 2.01  */

/* Standard headers */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <cogent.h>

/* Local headers */
#include "ablibs.h"
#include "abimport.h"
#include "proto.h"
#include "global.h"

#include "alarm_table.h"
#include "alarms.h"
#include "trenddb.h"

extern alarms_t *alarms; // defined in setup_all.c

#define DRIVE_1_NZAD		"Mentor_14_0117"
#define DRIVE_1_IA			"Mentor_14_0502"
#define DRIVE_1_UA			"Mentor_14_0304"
#define DRIVE_1_N			"Mentor_14_0303"
#define DRIVE_1_IV			"Mentor_13_0502"
#define DRIVE_1_M_OVRLD		"Mentor_14_0511"
#define DRIVE_1_S_OVRLD		"Mentor_12_0511"

#define DRIVE_2_NZAD		"Mentor_24_0117"
#define DRIVE_2_IA			"Mentor_24_0502"
#define DRIVE_2_UA			"Mentor_24_0304"
#define DRIVE_2_N			"Mentor_24_0303"
#define DRIVE_2_IV			"Mentor_23_0502"
#define DRIVE_2_M_OVRLD		"Mentor_24_0511"
#define DRIVE_2_S_OVRLD		"Mentor_22_0511"



static double get_dbl_value (char *name) 
{
	double out = 0;
	ST_STATUS	status;
	PT_stCPOINT point;

	static IP_Msg *hmsg;
	static IP_Task *myself;	

	if (!myself) {
		if (!(myself = IP_TaskCreateMe (IP_GetChannelID(), "ph_view", NULL, NULL, 0))) {
	    	fprintf (stderr, "Could not initialize Cascade IPC subsystem\n");
		}
	}
	if (!hmsg) {
		hmsg = IP_MsgCreate (NULL, IP_MsgDefaultSize(), 0);
	}
	
	memset (&point, 0, sizeof (point));
	point.name = name;
		
	if (myself) {
		if ((status = DH_ReadExistingPoint (myself, &point, hmsg, NULL)) == ST_OK) {
			out = point.value.r;
		} else {		
			fprintf (stderr, "Can't find point \"%s\" in datahub\n", name);
		}
	}
	
	//IP_TaskDestroy (myself);
	//IP_MsgDestroy (hmsg);
	return out;
}

static int get_int_value (char *name) 
{
	int out = 0;
	ST_STATUS	status;
	PT_stCPOINT point;

	static IP_Msg *hmsg;
	static IP_Task *myself;	

	if (!myself) {
		if (!(myself = IP_TaskCreateMe (IP_GetChannelID(), "ph_view", NULL, NULL, 0))) {
	    	fprintf (stderr, "Could not initialize Cascade IPC subsystem\n");
		}
	}
	if (!hmsg) {
		hmsg = IP_MsgCreate (NULL, IP_MsgDefaultSize(), 0);
	}
	
	memset (&point, 0, sizeof (point));
	point.name = name;
		
	if (myself) {
		if ((status = DH_ReadExistingPoint (myself, &point, hmsg, NULL)) == ST_OK) {
			out = point.value.i;
		} else {		
			fprintf (stderr, "Can't find point \"%s\" in datahub\n", name);
		}
	}

	//IP_TaskDestroy (myself);
	//IP_MsgDestroy (hmsg);
	return out;
}

int
main_timer ( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )
{
	unsigned short *ppi, pi;	
	unsigned short *selected;
	char str [255];
	double val;
	double Ia, Ua, Iv;
	int ival;
	PgColor_t color;
	int *flags;
	time_t tod;
	int reserve_status;
	//int i;

	/* eliminate 'unreferenced' warnings */
	widget = widget, apinfo = apinfo, cbinfo = cbinfo;
	
	if (cbinfo->reason == Pt_CB_PG_PANEL_SWITCHING) {
		PtPanelGroupCallback_t *data = (PtPanelGroupCallback_t *) cbinfo->cbdata;
		pi = data->new_panel_index;
	} else {
		PtGetResource (ABW_PtPanelGroup1, Pt_ARG_PG_CURRENT_INDEX, &ppi, 0);
		pi = *ppi;
	}

	//-----------------------------------------------------------------			
	// EP#1 Master Overload (5:11)
	val = get_dbl_value (DRIVE_1_M_OVRLD); 
	sprintf (str, "%.0f", val);
	PtSetResource (ABW_PtLabel_Master1_Ovrld, Pt_ARG_TEXT_STRING, str, 0);
	//-----------------------------------------------------------------	
	// EP#1 Slave Overload (5:11)
	val = get_dbl_value (DRIVE_1_S_OVRLD); 
	sprintf (str, "%.0f", val);
	PtSetResource (ABW_PtLabel_Slave1_Ovrld, Pt_ARG_TEXT_STRING, str, 0);
	//-----------------------------------------------------------------				
	// EP#2 Master Overload (5:11)
	val = get_dbl_value (DRIVE_2_M_OVRLD); 
	sprintf (str, "%.0f", val);
	PtSetResource (ABW_PtLabel_Master2_Ovrld, Pt_ARG_TEXT_STRING, str, 0);
	//-----------------------------------------------------------------	
	// EP#2 Slave Overload (5:11)
	val = get_dbl_value (DRIVE_2_S_OVRLD); 
	sprintf (str, "%.0f", val);
	PtSetResource (ABW_PtLabel_Slave2_Ovrld, Pt_ARG_TEXT_STRING, str, 0);
	//-----------------------------------------------------------------			
			
	switch (pi) {
		case 0:	
			//-----------------------------------------------------------------		
			// EP#1 Master Ia (5:02)
			Ia = get_dbl_value (DRIVE_1_IA); 
			PtSetResource (ABW_CwGauge_Ia1, GAUGE_ARG_POS, &Ia, 0);
			sprintf (str, "%.1f", Ia);
			PtSetResource (ABW_PtLabel_Ia1, Pt_ARG_TEXT_STRING, str, 0);
			//-----------------------------------------------------------------		
			// EP#1 Field Iv (5:02)
			Iv = get_dbl_value (DRIVE_1_IV); 
			PtSetResource (ABW_CwGauge_Iv1, GAUGE_ARG_POS, &Iv, 0);
			sprintf (str, "%.0f", Iv);
			PtSetResource (ABW_PtLabel_Iv1, Pt_ARG_TEXT_STRING, str, 0);
			//-----------------------------------------------------------------		
			// EP#1 Master Ua (3:04)
			Ua = get_dbl_value (DRIVE_1_UA); 
			PtSetResource (ABW_CwGauge_Ua1, GAUGE_ARG_POS, &Ua, 0);
			sprintf (str, "%.0f", Ua);
			PtSetResource (ABW_PtLabel_Ua1, Pt_ARG_TEXT_STRING, str, 0);
			//-----------------------------------------------------------------		
			// EP#1 Master
			// n = (Ua - Ia * R)/c
			// n = (Ua - Ia * 0.0615)/(3 + (Iv - 33.4)/22)
			//val = (Ua - Ia *1000 * 0.0615)/(3 + (Iv - 33.4)/22);
			val = get_dbl_value (DRIVE_1_N);
			PtSetResource (ABW_CwGauge_n1, GAUGE_ARG_POS, &val, 0);
			sprintf (str, "%.0f", val);
			PtSetResource (ABW_PtLabel_n1, Pt_ARG_TEXT_STRING, str, 0);
			//-----------------------------------------------------------------		
			// EP#1 Master nzad (1:17)
			val = get_dbl_value (DRIVE_1_NZAD); 
			PtSetResource (ABW_PtProgress_nzad1, Pt_ARG_GAUGE_VALUE, (int) val, 0);
			//-----------------------------------------------------------------		
			//-----------------------------------------------------------------		
			// EP#2 Master Ia (5:02)
			Ia = get_dbl_value (DRIVE_2_IA); 
			PtSetResource (ABW_CwGauge_Ia2, GAUGE_ARG_POS, &Ia, 0);
			sprintf (str, "%.1f", Ia);
			PtSetResource (ABW_PtLabel_Ia2, Pt_ARG_TEXT_STRING, str, 0);
			//-----------------------------------------------------------------		
			// EP#2 Field Iv (5:02)
			Iv = get_dbl_value (DRIVE_2_IV); 
			PtSetResource (ABW_CwGauge_Iv2, GAUGE_ARG_POS, &Iv, 0);
			sprintf (str, "%.0f", Iv);
			PtSetResource (ABW_PtLabel_Iv2, Pt_ARG_TEXT_STRING, str, 0);
			//-----------------------------------------------------------------		
			// EP#2 Master Ua (3:04)
			Ua = get_dbl_value (DRIVE_2_UA); 
			PtSetResource (ABW_CwGauge_Ua2, GAUGE_ARG_POS, &Ua, 0);
			sprintf (str, "%.0f", Ua);
			PtSetResource (ABW_PtLabel_Ua2, Pt_ARG_TEXT_STRING, str, 0);
			//-----------------------------------------------------------------		
			// EP#2 Master
			// n = (Ua - Ia * R)/c
			// n = (Ua - Ia * 0.0615)/(3 + (Iv - 33.4)/22)
			//val = (Ua - Ia *1000 * 0.0615)/(3 + (Iv - 33.4)/22);
			val = get_dbl_value (DRIVE_2_N);
			PtSetResource (ABW_CwGauge_n2, GAUGE_ARG_POS, &val, 0);
			sprintf (str, "%.0f", val);
			PtSetResource (ABW_PtLabel_n2, Pt_ARG_TEXT_STRING, str, 0);
			//-----------------------------------------------------------------		
			// EP#2 Master nzad (1:17)
			val = get_dbl_value (DRIVE_2_NZAD); 
			PtSetResource (ABW_PtProgress_nzad2, Pt_ARG_GAUGE_VALUE, (int) val, 0);
			//-----------------------------------------------------------------		
			//-----------------------------------------------------------------		
			// W 0.14 - резерв включен на Д1
			// W 0.15 - резерв включен на Д2
			reserve_status = (get_int_value ("CJ1M_WR_WRD_000000") >> 14)&3;
			switch (reserve_status) {
				case 0: 
					PtSetResource (ABW_EP1_Label, Pt_ARG_COLOR, Pg_BLACK, 0);
					PtSetResource (ABW_EP1_Label, Pt_ARG_TEXT_STRING, "ЭП 1 - основной", 0);
					PtSetResource (ABW_EP2_Label, Pt_ARG_COLOR, Pg_BLACK, 0);
					PtSetResource (ABW_EP2_Label, Pt_ARG_TEXT_STRING, "ЭП 2 - основной", 0);
					break;
				case 1: 
					PtSetResource (ABW_EP1_Label, Pt_ARG_COLOR, Pg_RED, 0);
					PtSetResource (ABW_EP1_Label, Pt_ARG_TEXT_STRING, "ЭП 1 - резервный", 0);
					PtSetResource (ABW_EP2_Label, Pt_ARG_COLOR, Pg_BLACK, 0);
					PtSetResource (ABW_EP2_Label, Pt_ARG_TEXT_STRING, "ЭП 2 - основной", 0);
					break;
				case 2: 
					PtSetResource (ABW_EP1_Label, Pt_ARG_COLOR, Pg_BLACK, 0);
					PtSetResource (ABW_EP1_Label, Pt_ARG_TEXT_STRING, "ЭП 1 - основной", 0);
					PtSetResource (ABW_EP2_Label, Pt_ARG_COLOR, Pg_RED, 0);
					PtSetResource (ABW_EP2_Label, Pt_ARG_TEXT_STRING, "ЭП 2 - резервный", 0);
					break;
				default: 
					PtSetResource (ABW_EP1_Label, Pt_ARG_COLOR, Pg_YELLOW, 0);
					PtSetResource (ABW_EP1_Label, Pt_ARG_TEXT_STRING, "ЭП 1 - ошибка", 0);
					PtSetResource (ABW_EP2_Label, Pt_ARG_COLOR, Pg_YELLOW, 0);
					PtSetResource (ABW_EP2_Label, Pt_ARG_TEXT_STRING, "ЭП 2 - ошибка", 0);
			}
			//-----------------------------------------------------------------		
			//== VA_vkl_1 =====================================================
			if ((((reserve_status == 0) || (reserve_status == 2)) && ((get_int_value ("CJ1M_CIO_WRD_002008") >> 2) &1)) ||
				((reserve_status == 1) && ((get_int_value ("CJ1M_CIO_WRD_002010") >> 2) &1))) {
				color = Pg_RED;
				strcpy (str, "ВА 1 включен");	
			} else {
				color = PgRGB (217, 217, 217);
				strcpy (str, "ВА 1 (отключен)");	
			}
			PtSetResource (ABW_VA_vkl_1, Pt_ARG_FILL_COLOR, color, 0);
			PtSetResource (ABW_VA_1_lbl, Pt_ARG_TEXT_STRING, str, 0);
			//== VAB_vkl_1 ====================================================
			if ((get_int_value ("CJ1M_CIO_WRD_002012") >> 6) &1) {
				color = Pg_RED;
				strcpy (str, "ВАБ 1 включен");	
			} else if ((get_int_value ("CJ1M_CIO_WRD_002012") >> 7) &1) {
				color = Pg_GREEN;
				strcpy (str, "ВАБ 1 отключен");	
			} else {
				color = PgRGB (217, 217, 217);
				strcpy (str, "ВАБ 1 (неизвестно)");	
			}
			PtSetResource (ABW_VAB_vkl_1, Pt_ARG_FILL_COLOR, color, 0);
			PtSetResource (ABW_VAB_1_lbl, Pt_ARG_TEXT_STRING, str, 0);
			//== TP_gotov_1 ===================================================
			//if ((get_int_value ("CJ1M_WR_WRD_000000") >> 0) &1) {
			if ((((reserve_status == 0) || (reserve_status == 2)) && ((get_int_value ("CJ1M_WR_WRD_000000") >> 0) &1)) ||
				((reserve_status == 1) && ((get_int_value ("CJ1M_WR_WRD_000000") >> 12) &1))) {
				color = Pg_GREEN;
				strcpy (str, "ТП 1 готов");	
			} else {
				color = PgRGB (217, 217, 217);
				strcpy (str, "ТП 1 (неизвестно)");	
			}
			PtSetResource (ABW_TP_gotov_1, Pt_ARG_FILL_COLOR, color, 0);
			PtSetResource (ABW_TP_1_lbl, Pt_ARG_TEXT_STRING, str, 0);
			//=================================================================
			//== VA_vkl_2 =====================================================
			if ((((reserve_status == 0) || (reserve_status == 1)) && ((get_int_value ("CJ1M_CIO_WRD_002009") >> 2) &1)) ||
				((reserve_status == 2) && ((get_int_value ("CJ1M_CIO_WRD_002010") >> 2) &1))) {
				color = Pg_RED;
				strcpy (str, "ВА 2 включен");	
			} else {
				color = PgRGB (217, 217, 217);
				strcpy (str, "ВА 2 (отключен)");	
			}
			PtSetResource (ABW_VA_vkl_2, Pt_ARG_FILL_COLOR, color, 0);
			PtSetResource (ABW_VA_2_lbl, Pt_ARG_TEXT_STRING, str, 0);
			//== VAB_vkl_2 ====================================================
			if ((get_int_value ("CJ1M_CIO_WRD_002012") >> 8) &1) {
				color = Pg_RED;
				strcpy (str, "ВАБ 2 включен");	
			} else if ((get_int_value ("CJ1M_CIO_WRD_002012") >> 5) &1) {
				color = Pg_GREEN;
				strcpy (str, "ВАБ 2 отключен");	
			} else {
				color = PgRGB (217, 217, 217);
				strcpy (str, "ВАБ 2 (неизвестно)");	
			}
			PtSetResource (ABW_VAB_vkl_2, Pt_ARG_FILL_COLOR, color, 0);
			PtSetResource (ABW_VAB_2_lbl, Pt_ARG_TEXT_STRING, str, 0);
			//== TP_gotov_2 ===================================================
			//if ((get_int_value ("CJ1M_WR_WRD_000000") >> 11) &1) {
			if ((((reserve_status == 0) || (reserve_status == 1)) && ((get_int_value ("CJ1M_WR_WRD_000000") >> 11) &1)) ||
				((reserve_status == 2) && ((get_int_value ("CJ1M_WR_WRD_000000") >> 12) &1))) {
				color = Pg_GREEN;
				strcpy (str, "ТП 2 готов");	
			} else {
				color = PgRGB (217, 217, 217);
				strcpy (str, "ТП 2 (неизвестно)");	
			}
			PtSetResource (ABW_TP_gotov_2, Pt_ARG_FILL_COLOR, color, 0);
			PtSetResource (ABW_TP_2_lbl, Pt_ARG_TEXT_STRING, str, 0);
			//== alarm_lo_pri =================================================
			if ((get_int_value ("alarm_lo_prio")) == 1) {
				color = Pg_YELLOW;
			} else {
				color = PgRGB (217, 217, 217);
			}
			PtSetResource (ABW_alarm_lo_pri, Pt_ARG_FILL_COLOR, color, 0);
			//== alarm_hi_pri =================================================
			if ((get_int_value ("alarm_hi_prio")) == 1) {
				color = Pg_RED;
			} else {
				color = PgRGB (217, 217, 217);
			}
			PtSetResource (ABW_alarm_hi_pri, Pt_ARG_FILL_COLOR, color, 0);
			//=================================================================
			//-----------------------------------------------------------------		
			break;
		case 1:
			PtGetResource (ABW_Pause1, Pt_ARG_FLAGS, &flags, 0); // пауза
			if (!(*flags & Pt_SET)) {
				PtSetResource (ABW_CwTrend1, TREND_ARG_TIME_END, time (&tod), 0);
				PtSetResource (ABW_CwTrend1, TREND_ARG_LOAD_DATA, 0, 0);
			}
			break;
		case 2:
			PtGetResource (ABW_Pause2, Pt_ARG_FLAGS, &flags, 0); // пауза
			if (!(*flags & Pt_SET)) {
				PtSetResource (ABW_CwTrend2, TREND_ARG_TIME_END, time (&tod), 0);
				PtSetResource (ABW_CwTrend2, TREND_ARG_LOAD_DATA, 0, 0);				
			}
			break;
		case 3:
			PtGetResource (ABW_PtPanelGroup2, Pt_ARG_PG_CURRENT_INDEX, &ppi, 0);
			switch (*ppi) {
				case 0:
					// alarms list
					PtGetResource (ABW_ComboAlarms, Pt_ARG_CBOX_SEL_ITEM, &selected, 0);
					read_alarms (ABW_AlarmsList, *selected, 0);	
					break;					
				case 1:				
					// active alarms list
					PtDamageWidget (ABW_ActiveAlarmsList); 
					break;
			}
			break;
		case 4:
			PtDamageWidget (ABW_CwLadder1);
			break;
		case 5:
			ival = get_int_value ("CJ1M_WR_WRD_000000");
			// W 0.14 - резерв включен на Д1
			// W 0.15 - резерв включен на Д2
			switch ((ival >> 14)&3) {
				case 0: 
					PtSetResource (ABW_PR1, Cw_RECT_ARG_TYPE, 4, 0);
					PtSetResource (ABW_PR2, Cw_RECT_ARG_TYPE, 5, 0);
					break;
				case 1: 
					PtSetResource (ABW_PR1, Cw_RECT_ARG_TYPE, 5, 0);
					PtSetResource (ABW_PR2, Cw_RECT_ARG_TYPE, 5, 0);
					break;
				case 2: 
					PtSetResource (ABW_PR1, Cw_RECT_ARG_TYPE, 4, 0);
					PtSetResource (ABW_PR2, Cw_RECT_ARG_TYPE, 4, 0);
					break;
				default: 
					PtSetResource (ABW_PR1, Cw_RECT_ARG_TYPE, 7, 0);
					PtSetResource (ABW_PR2, Cw_RECT_ARG_TYPE, 7, 0);
			}
			if ((ival >> 0)&1) {
				PtSetResource (ABW_ShPT1, Pt_ARG_COLOR, Pg_GREEN, 0);
			} else {
				PtSetResource (ABW_ShPT1, Pt_ARG_COLOR, Pg_YELLOW, 0);
			}				
			if ((ival >> 11)&1) {
				PtSetResource (ABW_ShPT2, Pt_ARG_COLOR, Pg_GREEN, 0);
			} else {
				PtSetResource (ABW_ShPT2, Pt_ARG_COLOR, Pg_YELLOW, 0);
			}				
			if ((ival >> 12)&1) {
				PtSetResource (ABW_ShPTR, Pt_ARG_COLOR, Pg_GREEN, 0);
			} else {
				PtSetResource (ABW_ShPTR, Pt_ARG_COLOR, Pg_YELLOW, 0);
			}				

			ival = get_int_value ("CJ1M_WR_WRD_000004");
			if ((ival >> 12)&1) {
				PtSetResource (ABW_T14, Cw_RECT_ARG_DRAW_RECT, 1, 0);
				PtSetResource (ABW_T14, Cw_RECT_ARG_COLOR, Pg_RED, 0);
			} else {
				PtSetResource (ABW_T14, Cw_RECT_ARG_DRAW_RECT, 0, 0);
			}		
			if ((ival >> 13)&1) {
				PtSetResource (ABW_T13, Cw_RECT_ARG_DRAW_RECT, 1, 0);
				PtSetResource (ABW_T13, Cw_RECT_ARG_COLOR, Pg_RED, 0);
			} else {
				PtSetResource (ABW_T13, Cw_RECT_ARG_DRAW_RECT, 0, 0);
			}		
			if ((ival >> 14)&1) {
				PtSetResource (ABW_RT, Cw_RECT_ARG_DRAW_RECT, 1, 0);
				PtSetResource (ABW_RT, Cw_RECT_ARG_COLOR, Pg_RED, 0);
			} else {
				PtSetResource (ABW_RT, Cw_RECT_ARG_DRAW_RECT, 0, 0);
			}		

			ival = get_int_value ("CJ1M_WR_WRD_000022");
			if ((ival >> 3)&1) {
				PtSetResource (ABW_VAB1, Cw_RECT_ARG_DRAW_RECT, 1, 0);
				PtSetResource (ABW_VAB1, Cw_RECT_ARG_COLOR, Pg_RED, 0);
			} else {
				PtSetResource (ABW_VAB1, Cw_RECT_ARG_DRAW_RECT, 0, 0);
			}		
			if ((ival >> 4)&1) {
				PtSetResource (ABW_VAB2, Cw_RECT_ARG_DRAW_RECT, 1, 0);
				PtSetResource (ABW_VAB2, Cw_RECT_ARG_COLOR, Pg_RED, 0);
			} else {
				PtSetResource (ABW_VAB2, Cw_RECT_ARG_DRAW_RECT, 0, 0);
			}		
			if ((ival >> 5)&1) {
				PtSetResource (ABW_M1, Cw_RECT_ARG_DRAW_RECT, 1, 0);
				PtSetResource (ABW_M1, Cw_RECT_ARG_COLOR, Pg_RED, 0);
			} else {
				PtSetResource (ABW_M1, Cw_RECT_ARG_DRAW_RECT, 0, 0);
			}		
			if ((ival >> 6)&1) {
				PtSetResource (ABW_M2, Cw_RECT_ARG_DRAW_RECT, 1, 0);
				PtSetResource (ABW_M2, Cw_RECT_ARG_COLOR, Pg_RED, 0);
			} else {
				PtSetResource (ABW_M2, Cw_RECT_ARG_DRAW_RECT, 0, 0);
			}		

			ival = get_int_value ("CJ1M_WR_WRD_000024");
			if ((ival >> 14)&1) {
				PtSetResource (ABW_OV1, Cw_RECT_ARG_DRAW_RECT, 1, 0);
				PtSetResource (ABW_OV1, Cw_RECT_ARG_COLOR, Pg_RED, 0);
			} else {
				PtSetResource (ABW_OV1, Cw_RECT_ARG_DRAW_RECT, 0, 0);
			}		
			if ((ival >> 15)&1) {
				PtSetResource (ABW_OV2, Cw_RECT_ARG_DRAW_RECT, 1, 0);
				PtSetResource (ABW_OV2, Cw_RECT_ARG_COLOR, Pg_RED, 0);
			} else {
				PtSetResource (ABW_OV2, Cw_RECT_ARG_DRAW_RECT, 0, 0);
			}		

			ival = get_int_value ("CJ1M_CIO_WRD_002008");
			if ((ival >> 2)&1) {
				PtSetResource (ABW_VV14, Pt_ARG_COLOR, Pg_GREEN, 0);
				PtSetResource (ABW_T14, Pt_ARG_COLOR, Pg_GREEN, 0);
				PtSetResource (ABW_VV14, Cw_RECT_ARG_TYPE, 2, 0);
			} else {
				PtSetResource (ABW_VV14, Pt_ARG_COLOR, Pg_YELLOW, 0);
				PtSetResource (ABW_T14, Pt_ARG_COLOR, Pg_YELLOW, 0);
				PtSetResource (ABW_VV14, Cw_RECT_ARG_TYPE, 1, 0);
			}		
			if ((ival >> 14)&1) {
				PtSetResource (ABW_ShPT1_TV, Pt_ARG_COLOR, Pg_GREEN, 0);
			} else {
				PtSetResource (ABW_ShPT1_TV, Pt_ARG_COLOR, Pg_YELLOW, 0);
			}			
			if ((ival >> 10)&1) {
				PtSetResource (ABW_ShPT1_TP1, Pt_ARG_COLOR, Pg_GREEN, 0);
			} else {
				PtSetResource (ABW_ShPT1_TP1, Pt_ARG_COLOR, Pg_YELLOW, 0);
			}			
			if ((ival >> 11)&1) {
				PtSetResource (ABW_ShPT1_TP2, Pt_ARG_COLOR, Pg_GREEN, 0);
			} else {
				PtSetResource (ABW_ShPT1_TP2, Pt_ARG_COLOR, Pg_YELLOW, 0);
			}			
			if ((ival >> 0)&1) {
				PtSetResource (ABW_ShPT1_QF1, Pt_ARG_COLOR, Pg_GREEN, 0);
				PtSetResource (ABW_ShPT1_QF2, Pt_ARG_COLOR, Pg_GREEN, 0);
				PtSetResource (ABW_ShPT1_QF1, Cw_RECT_ARG_TYPE, 2, 0);
				PtSetResource (ABW_ShPT1_QF2, Cw_RECT_ARG_TYPE, 2, 0);				
			} else {
				PtSetResource (ABW_ShPT1_QF1, Pt_ARG_COLOR, Pg_YELLOW, 0);
				PtSetResource (ABW_ShPT1_QF2, Pt_ARG_COLOR, Pg_YELLOW, 0);
				PtSetResource (ABW_ShPT1_QF1, Cw_RECT_ARG_TYPE, 1, 0);
				PtSetResource (ABW_ShPT1_QF2, Cw_RECT_ARG_TYPE, 1, 0);
			}			
			
			ival = get_int_value ("CJ1M_CIO_WRD_002009");
			if ((ival >> 2)&1) {
				PtSetResource (ABW_VV13, Pt_ARG_COLOR, Pg_GREEN, 0);
				PtSetResource (ABW_T13, Pt_ARG_COLOR, Pg_GREEN, 0);
				PtSetResource (ABW_VV13, Cw_RECT_ARG_TYPE, 2, 0);
			} else {
				PtSetResource (ABW_VV13, Pt_ARG_COLOR, Pg_YELLOW, 0);
				PtSetResource (ABW_T13, Pt_ARG_COLOR, Pg_YELLOW, 0);
				PtSetResource (ABW_VV13, Cw_RECT_ARG_TYPE, 1, 0);
			}		
			if ((ival >> 14)&1) {
				PtSetResource (ABW_ShPT2_TV, Pt_ARG_COLOR, Pg_GREEN, 0);
			} else {
				PtSetResource (ABW_ShPT2_TV, Pt_ARG_COLOR, Pg_YELLOW, 0);
			}			
			if ((ival >> 10)&1) {
				PtSetResource (ABW_ShPT2_TP1, Pt_ARG_COLOR, Pg_GREEN, 0);
			} else {
				PtSetResource (ABW_ShPT2_TP1, Pt_ARG_COLOR, Pg_YELLOW, 0);
			}			
			if ((ival >> 11)&1) {
				PtSetResource (ABW_ShPT2_TP2, Pt_ARG_COLOR, Pg_GREEN, 0);
			} else {
				PtSetResource (ABW_ShPT2_TP2, Pt_ARG_COLOR, Pg_YELLOW, 0);
			}			
			if ((ival >> 0)&1) {
				PtSetResource (ABW_ShPT2_QF1, Pt_ARG_COLOR, Pg_GREEN, 0);
				PtSetResource (ABW_ShPT2_QF2, Pt_ARG_COLOR, Pg_GREEN, 0);
				PtSetResource (ABW_ShPT2_QF1, Cw_RECT_ARG_TYPE, 2, 0);
				PtSetResource (ABW_ShPT2_QF2, Cw_RECT_ARG_TYPE, 2, 0);				
			} else {
				PtSetResource (ABW_ShPT2_QF1, Pt_ARG_COLOR, Pg_YELLOW, 0);
				PtSetResource (ABW_ShPT2_QF2, Pt_ARG_COLOR, Pg_YELLOW, 0);
				PtSetResource (ABW_ShPT2_QF1, Cw_RECT_ARG_TYPE, 1, 0);
				PtSetResource (ABW_ShPT2_QF2, Cw_RECT_ARG_TYPE, 1, 0);
			}						

			ival = get_int_value ("CJ1M_CIO_WRD_002010");
			if ((ival >> 2)&1) {
				PtSetResource (ABW_VV1, Pt_ARG_COLOR, Pg_GREEN, 0);
				PtSetResource (ABW_RT, Pt_ARG_COLOR, Pg_GREEN, 0);
				PtSetResource (ABW_VV1, Cw_RECT_ARG_TYPE, 2, 0);
			} else {
				PtSetResource (ABW_VV1, Pt_ARG_COLOR, Pg_YELLOW, 0);
				PtSetResource (ABW_RT, Pt_ARG_COLOR, Pg_YELLOW, 0);
				PtSetResource (ABW_VV1, Cw_RECT_ARG_TYPE, 1, 0);
			}		
			if ((ival >> 14)&1) {
				PtSetResource (ABW_ShPTR_TV, Pt_ARG_COLOR, Pg_GREEN, 0);
			} else {
				PtSetResource (ABW_ShPTR_TV, Pt_ARG_COLOR, Pg_YELLOW, 0);
			}			
			if ((ival >> 10)&1) {
				PtSetResource (ABW_ShPTR_TP1, Pt_ARG_COLOR, Pg_GREEN, 0);
			} else {
				PtSetResource (ABW_ShPTR_TP1, Pt_ARG_COLOR, Pg_YELLOW, 0);
			}			
			if ((ival >> 11)&1) {
				PtSetResource (ABW_ShPTR_TP2, Pt_ARG_COLOR, Pg_GREEN, 0);
			} else {
				PtSetResource (ABW_ShPTR_TP2, Pt_ARG_COLOR, Pg_YELLOW, 0);
			}			
			if ((ival >> 0)&1) {
				PtSetResource (ABW_ShPTR_QF1, Pt_ARG_COLOR, Pg_GREEN, 0);
				PtSetResource (ABW_ShPTR_QF2, Pt_ARG_COLOR, Pg_GREEN, 0);
				PtSetResource (ABW_ShPTR_QF1, Cw_RECT_ARG_TYPE, 2, 0);
				PtSetResource (ABW_ShPTR_QF2, Cw_RECT_ARG_TYPE, 2, 0);				
			} else {
				PtSetResource (ABW_ShPTR_QF1, Pt_ARG_COLOR, Pg_YELLOW, 0);
				PtSetResource (ABW_ShPTR_QF2, Pt_ARG_COLOR, Pg_YELLOW, 0);
				PtSetResource (ABW_ShPTR_QF1, Cw_RECT_ARG_TYPE, 1, 0);
				PtSetResource (ABW_ShPTR_QF2, Cw_RECT_ARG_TYPE, 1, 0);
			}			

			ival = get_int_value ("CJ1M_CIO_WRD_002011");
			if ((ival >> 4)&1) {
				PtSetResource (ABW_OV1, Pt_ARG_COLOR, Pg_GREEN, 0);
			} else {
				PtSetResource (ABW_OV1, Pt_ARG_COLOR, Pg_YELLOW, 0);
			}		
			if ((ival >> 5)&1) {
				PtSetResource (ABW_OV2, Pt_ARG_COLOR, Pg_GREEN, 0);
			} else {
				PtSetResource (ABW_OV2, Pt_ARG_COLOR, Pg_YELLOW, 0);
			}		
						
			ival = get_int_value ("CJ1M_CIO_WRD_002012");
			if ((ival >> 6)&1) {
				PtSetResource (ABW_VAB1, Pt_ARG_COLOR, Pg_GREEN, 0);
				PtSetResource (ABW_VAB1, Cw_RECT_ARG_TYPE, 2, 0);
			} else {
				PtSetResource (ABW_VAB1, Pt_ARG_COLOR, Pg_YELLOW, 0);
				PtSetResource (ABW_VAB1, Cw_RECT_ARG_TYPE, 1, 0);
			}		
			if ((ival >> 8)&1) {
				PtSetResource (ABW_VAB2, Pt_ARG_COLOR, Pg_GREEN, 0);
				PtSetResource (ABW_VAB2, Cw_RECT_ARG_TYPE, 2, 0);
			} else {
				PtSetResource (ABW_VAB2, Pt_ARG_COLOR, Pg_YELLOW, 0);
				PtSetResource (ABW_VAB2, Cw_RECT_ARG_TYPE, 1, 0);
			}		

			//-------------------------------------
			ival = get_int_value ("CJ1M_CIO_WRD_002016");
			if ((ival >> 0)&1) {
				PtSetResource (ABW_RO1_rect, Pt_ARG_COLOR, Pg_GREEN, 0);
			} else {
				PtSetResource (ABW_RO1_rect, Pt_ARG_COLOR, Pg_RED, 0);
			}		
			if ((ival >> 1)&1) {
				PtSetResource (ABW_RO2_rect, Pt_ARG_COLOR, Pg_GREEN, 0);
			} else {
				PtSetResource (ABW_RO2_rect, Pt_ARG_COLOR, Pg_RED, 0);
			}						
			if ((ival >> 2)&1) {
				PtSetResource (ABW_RO3_rect, Pt_ARG_COLOR, Pg_GREEN, 0);
			} else {
				PtSetResource (ABW_RO3_rect, Pt_ARG_COLOR, Pg_RED, 0);
			}			
			if ((ival >> 3)&1) {
				PtSetResource (ABW_RO4_rect, Pt_ARG_COLOR, Pg_GREEN, 0);
			} else {
				PtSetResource (ABW_RO4_rect, Pt_ARG_COLOR, Pg_RED, 0);
			}					
			
			ival = get_int_value ("CJ1M_CIO_WRD_002017");			
			if ((ival >> 0)&1) {
				PtSetResource (ABW_ID1_rect, Pt_ARG_COLOR, Pg_GREEN, 0);
			} else {
				PtSetResource (ABW_ID1_rect, Pt_ARG_COLOR, Pg_RED, 0);
			}				
			if ((ival >> 1)&1) {
				PtSetResource (ABW_ID2_rect, Pt_ARG_COLOR, Pg_GREEN, 0);
			} else {
				PtSetResource (ABW_ID2_rect, Pt_ARG_COLOR, Pg_RED, 0);
			}									
			if ((ival >> 2)&1) {
				PtSetResource (ABW_ID3_rect, Pt_ARG_COLOR, Pg_GREEN, 0);
			} else {
				PtSetResource (ABW_ID3_rect, Pt_ARG_COLOR, Pg_RED, 0);
			}							
			if ((ival >> 3)&1) {
				PtSetResource (ABW_ID4_rect, Pt_ARG_COLOR, Pg_GREEN, 0);
			} else {
				PtSetResource (ABW_ID4_rect, Pt_ARG_COLOR, Pg_RED, 0);
			}								
			if ((ival >> 4)&1) {
				PtSetResource (ABW_ID5_rect, Pt_ARG_COLOR, Pg_GREEN, 0);
			} else {
				PtSetResource (ABW_ID5_rect, Pt_ARG_COLOR, Pg_RED, 0);
			}									
			break;
	}
	
	
	return ( Pt_CONTINUE );
}